{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization: PyntCloud"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## [Run this notebook on binder](https://mybinder.org/v2/gh/daavoo/pyntcloud/master)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this notebook we are going to learn about the different available options for visualizing PyntClouds."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyntcloud import PyntCloud"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load ankylosaurus mesh"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We are going to load a 3D model of an ankylosaurus from the provided `examples/data.`\n",
    "\n",
    "You could load other point cloud in any of the supported [point cloud formats](http://pyntcloud.readthedocs.io/en/latest/io.html).\n",
    "\n",
    "You can learn more about reading and writing point clouds in the `examples/[io]` notebooks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PyntCloud\n",
       "34820 points with 6 scalar fields\n",
       "69636 faces in mesh\n",
       "0 kdtrees\n",
       "0 voxelgrids\n",
       "Centroid: 0.029972486197948456, 1.1250594854354858, 2.887650489807129\n",
       "Other attributes:"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "anky = PyntCloud.from_file(\"data/ankylosaurus_mesh.ply\")\n",
    "anky"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the description, we can see that this is a 3D mesh with 69636 faces. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization: Mesh"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "We can visualize the mesh with the `plot` method.\n",
    "\n",
    "Note that we are passing the argument `backend=\"threejs\"` because mesh visualziation is not currently supported with the default backend. \n",
    "\n",
    "Because of this, the visualization might don't work in some enviroments (i.e. binder). We are working to add support to mesh plotting with the default backend as soon as possible  in order to fix these issues."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "anky.plot(mesh=True, backend=\"threejs\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![mesh](data/images/structures-voxelgrid-1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Convert Mesh to Point Cloud using random sampling."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can now convert the mesh into a point cloud by sampling 100.000 random points from the surface.\n",
    "\n",
    "You cand learn more about hoy to convert a triangular mesh into a point cloud in the `examples/[sampling]` notebooks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "anky_cloud = anky.get_sample(\n",
    "    \"mesh_random\", n=100000, rgb=True, normals=True, as_PyntCloud=True\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that we pass the `normals=True` argument so now our point cloud has normal values for each point."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization: Pandas built-in"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Because PyntCloud.points is a pandas.DataFrame, we can leverage the built-in [visualization options of pandas](https://pandas.pydata.org/pandas-docs/stable/visualization.html):"
   ]
  },
  {
   "cell_type": "code",
   "execution_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7ara9JU2+IOly4ILBzJWGl4iIByWtAN4MXEuL95ek/YDfAJ9PQwPVbfd7f9XR0+9LvWUqkvYE9icb0sizbpG5kPRuskL9toh4odrew8+0Gf9I9pkrIrpqZn8EfK1m3bd3W3dFEzLlylXjVGBBbUOB+6svPeUuZF95+Kt/6j4eJrKzX78jO58BMAfIc+STx7K0vTzb3W0sN/3DWj2P8X6g7pUiReSSdEB1+EjSBOAtwJ9avb/Sz+46svHma7p91sz9ledxQrV5PwDcmvbPMuBUZVeHTQGmAncNIEtDuSS9GfghcGJEPFp7nyNFAAABSElEQVTTXvdnOoi5JtbMngjcl6aXA7NTvgOA2bz8iL3QXCnb68hOfN9e01bk/urLMuD0dBXYMcCT6Y+mYvZVEVcjlPkLOJmsgr8APAIsT+2vAW6sWe69wH+R/aXxuZr2Q8n+p98AXAPs3aRc44FbgPXp+7jUPgv4cc1yHcBfgD26rX8rsIbsH8efAK8crFzAP6S+/zN9P2so7C/gY8AO4J6aryOK2F/1fl/IhtNOTNNt6b9/Q9ofh9as+7m03v3A8U3+fe8r183p/4Pq/lnW1890kHJ9FViX+v8d8Pqadc9M+3EDMHcwc6X5i4FLuq1X2P4i+wNyS/pdrpCd+/ok8Mn0ucheZvhA6ntWzbpN31e+o97MzJrGw19mZtY0LipmZtY0LipmZtY0LipmZtY0LipmZtY0LipmZtY0LipmZtY0LipmZtY0/x+ln/ATyusPnQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "anky_cloud.points[[\"nx\", \"ny\", \"nz\"]].plot(kind=\"hist\", subplots=True);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization: Point Cloud"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can visualize the sampled point cloud as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d268d7c7b86744a4b5917461b6933af7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Renderer(camera=PerspectiveCamera(aspect=1.6, fov=90.0, position=(0.016195666044950485, 2.416865110397339, 9.2…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a05fab562dbe4d55854604f7869ec724",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(Label(value='Background color:'), ColorPicker(value='black'), Label(value='Point size:'), Float…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "scene = anky_cloud.plot(return_scene=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![anky_cloud](data/images/structures-voxelgrid-2.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use the interactive widgets bellow the plot to dynamically adjust the background color and the point size."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Custom scalar field with custom color map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can select any of the scalar fields in a PyntCloud (any name in the DataFrame PyntCloud.points) and use it to colorize the point cloud. \n",
    "\n",
    "We do this with the `use_as_color` argument."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also select any of the [avaliable color maps in Matplotlib](https://matplotlib.org/examples/color/colormaps_reference.html) adjust the colorization.\n",
    "\n",
    "We do this with the `cmap` argument."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "anky_cloud.plot(use_as_color=\"x\", cmap=\"cool\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![anky_cloud](data/images/visualization-PyntCloud-1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization: Multiple Point Clouds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can visualize multiple point clouds on the seame scene."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First, we generate a new point cloud by randomly sampling 100 points:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "anky_cloud_sample = anky_cloud.get_sample(\"points_random\", n=100, as_PyntCloud=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We set the color of that sample to red for easier visualization:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "anky_cloud_sample.points[\"red\"] = 255\n",
    "anky_cloud_sample.points[\"green\"] = 0\n",
    "anky_cloud_sample.points[\"blue\"] = 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we plot the original point cloud and we use the `return_scene=True` argument to store the pythreejs scene in a variable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "65975decc72643eea41652c7c34a12dd",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Renderer(camera=PerspectiveCamera(aspect=1.6, fov=90.0, position=(0.014691604301333427, 2.4172754287719727, 7.…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b0ee28a0fdc84353ae130be5d683eb70",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(Label(value='Point size:'), FloatSlider(value=0.01, max=0.1, step=0.0001), Label(value='Backgro…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "scene = anky_cloud.plot(initial_point_size=0.01, return_scene=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can pass that variable using the `scene` argument when we call the plot function on our sampled point cloud:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7985804b4c53403bbcddab039805579d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(Label(value='Point size:'), FloatSlider(value=0.05, max=0.5, step=0.0005)))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "anky_cloud_sample.plot(initial_point_size=0.05, scene=scene)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
